package smecta.client.print.controller;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class ProductSettingsViewController {

	@FXML
	private TreeView<String> treeView;

	@FXML
	private StackPane contentPane;

	@FXML
	private ImageView logoImage;

	@FXML
	private VBox tableContainer;

	@FXML
	private TableView<?> tableView;

	@FXML
	private TableColumn<?, ?> col1;

	@FXML
	private TableColumn<?, ?> col2;

	@FXML
	private TableColumn<?, ?> col3;

	@FXML
	private TableColumn<?, ?> col4;

	@FXML
	private Button addButton;

	@FXML
	private Button deleteButton;

	@FXML
	private Button saveButton;

	@FXML
	private Button exportButton;

	@FXML
	private Button closeButton;

	@FXML
	private void handleAdd() {
		// ���������߼�
		System.out.println("����");
	}

	@FXML
	private void handleDelete() {
		System.out.println("handleDelete");
	}

	@FXML
	private void handleSave() {
		System.out.println("handleSave");
	}

	@FXML
	private void handleExport() {
		System.out.println("handleExport");
	}

	@FXML
	private void handleClose() {
		Stage stage = (Stage) closeButton.getScene().getWindow();
		stage.close();
	}

	@FXML
	public void initialize() {
		treeView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<TreeItem<String>>() {
			@Override
			public void changed(ObservableValue<? extends TreeItem<String>> observable, TreeItem<String> oldValue,
					TreeItem<String> newValue) {
				if (newValue != null) {
					handleTreeSelection(newValue);
				}
			}
		});
	}

	private void handleTreeSelection(TreeItem<String> selectedItem) {
		String selectedItemValue = selectedItem.getValue();

		if (selectedItemValue != null) {
			logoImage.setVisible(false);
			tableContainer.setVisible(true);
			//TODO
			col1.setText(selectedItemValue + "TODO1");
			col2.setText(selectedItemValue + "TODO2");
			col3.setText(selectedItemValue + " TODO3");
			col4.setText(selectedItemValue + " TODO4");
		} else {
			logoImage.setVisible(true);
			tableContainer.setVisible(false);
		}
	}
}
